import { AdminUserModule } from './module/admin-user/admin-user.module';
import { Module, Logger } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { GraphQLModule } from '@nestjs/graphql';
import { ConfigProvider } from './config/config.provider';
import { TypeOrmModule } from '@nestjs/typeorm';
import { MenuModule } from './module/menu/menu.module';

@Module({
  imports: [TypeOrmModule.forRoot(ConfigProvider.getConfig('db')),
  GraphQLModule.forRoot({
    context: ({ req, res }) => ({ req, res }),
    installSubscriptionHandlers: true,
    typePaths: ['./**/*.graphql'],
    autoSchemaFile: 'schema.gql',
    formatError: (error): any => {
      Logger.error(error, '', 'GraphQLError');
      return error;
    },
  }), AdminUserModule, MenuModule],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule { }
